

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="dayu">
  <meta name="keywords" content="">
  
    <meta name="description" content="库存销量分析代码环境的准备StockPage.vue 12345678910111213141516171819202122&lt;!--针对于 &#x2F;stockpage 这条路径而显示出来的在这个组件中, 通过子组件注册的方式, 要显示出Stock.vue这个组件--&gt;&lt;template&gt;  &lt;div class&#x3D;&quot;com-page&quot;&gt;    &amp;lt">
<meta property="og:type" content="article">
<meta property="og:title" content="数据可视化项目七">
<meta property="og:url" content="http://example.com/2022/11/17/%E6%95%B0%E6%8D%AE%E5%8F%AF%E8%A7%86%E5%8C%96%E9%A1%B9%E7%9B%AE%E5%85%AB/index.html">
<meta property="og:site_name" content="Dayu">
<meta property="og:description" content="库存销量分析代码环境的准备StockPage.vue 12345678910111213141516171819202122&lt;!--针对于 &#x2F;stockpage 这条路径而显示出来的在这个组件中, 通过子组件注册的方式, 要显示出Stock.vue这个组件--&gt;&lt;template&gt;  &lt;div class&#x3D;&quot;com-page&quot;&gt;    &amp;lt">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2022-11-17T12:18:32.000Z">
<meta property="article:modified_time" content="2023-09-05T13:21:06.567Z">
<meta property="article:author" content="dayu">
<meta property="article:tag" content="echarts">
<meta name="twitter:card" content="summary_large_image">
  
  
  
  <title>数据可视化项目七 - Dayu</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.3","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 5.4.2"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>dayu</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="数据可视化项目七"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-11-17 20:18" pubdate>
          2022年11月17日 晚上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          9.9k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          83 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">数据可视化项目七</h1>
            
            
              <div class="markdown-body">
                
                <h1 id="库存销量分析"><a href="#库存销量分析" class="headerlink" title="库存销量分析"></a>库存销量分析</h1><h2 id="代码环境的准备"><a href="#代码环境的准备" class="headerlink" title="代码环境的准备"></a>代码环境的准备</h2><p><code>StockPage.vue</code></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;!--<br>针对于 /stockpage 这条路径而显示出来的<br>在这个组件中, 通过子组件注册的方式, 要显示出Stock.vue这个组件<br>--&gt;<br>&lt;template&gt;<br>  &lt;div class=&quot;com-page&quot;&gt;<br>    &lt;stock&gt;&lt;/stock&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br>&lt;script&gt;<br>import Stock from &#x27;@/components/Stock&#x27;<br>export default &#123;<br>  data() &#123;<br>    return &#123;&#125;<br>  &#125;,<br>  methods: &#123;&#125;,<br>  components: &#123;<br>    stock: Stock,<br>  &#125;,<br>&#125;<br>&lt;/script&gt;<br>&lt;style lang=&quot;less&quot; scoped&gt;&lt;/style&gt;<br></code></pre></td></tr></table></figure>

<p><code>Stock.vue</code></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;!-- 库存销量分析 --&gt;<br>&lt;template&gt;<br>  &lt;div class=&quot;com-container&quot;&gt;<br>    &lt;div class=&quot;com-chart&quot; ref=&quot;stock_ref&quot;&gt;&lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br>&lt;script&gt;<br>export default &#123;<br>  data() &#123;<br>    return &#123;<br>      chartInstance: null,<br>      allData: null,<br>    &#125;<br>  &#125;,<br>  mounted() &#123;<br>    this.initChart()<br>    this.getData()<br>    window.addEventListener(&#x27;resize&#x27;, this.screenAdapter)<br>    this.screenAdapter()<br>  &#125;,<br>  destroyed() &#123;<br>    window.removeEventListener(&#x27;resize&#x27;, this.screenAdapter)<br>  &#125;,<br>  methods: &#123;<br>    initChart() &#123;<br>      this.chartInstance = this.$echarts.init(this.$refs.stock_ref)<br>      const initOption = &#123;&#125;<br>      this.chartInstance.setOption(initOption)<br>    &#125;,<br>    async getData() &#123;<br>      // 获取服务器的数据, 对this.allData进行赋值之后, 调用updateChart方法更新图表<br>      this.updateChart()<br>    &#125;,<br>    updateChart() &#123;<br>      // 处理图表需要的数据<br>      const dataOption = &#123;&#125;<br>      this.chartInstance.setOption(dataOption)<br>    &#125;,<br>    screenAdapter() &#123;<br>      const adapterOption = &#123;&#125;<br>      this.chartInstance.setOption(adapterOption)<br>      this.chartInstance.resize()<br>    &#125;,<br>  &#125;,<br>&#125;<br>&lt;/script&gt;<br>&lt;style lang=&quot;less&quot; scoped&gt;&lt;/style&gt;<br></code></pre></td></tr></table></figure>

<p><code>router/index.js</code></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs js">......<br><span class="hljs-keyword">import</span> <span class="hljs-title class_">StockPage</span> <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@/views/StockPage&#x27;</span><br>......<br><span class="hljs-keyword">const</span> routes = [<br>......<br>&#123;<br><span class="hljs-attr">path</span>: <span class="hljs-string">&#x27;/stockpage&#x27;</span>,<br><span class="hljs-attr">component</span>: <span class="hljs-title class_">StockPage</span><br>&#125;<br>]<br>......<br></code></pre></td></tr></table></figure>

<h2 id="图表基本功能的实现"><a href="#图表基本功能的实现" class="headerlink" title="图表基本功能的实现"></a>图表基本功能的实现</h2><ul>
<li><p>数据的获取</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-keyword">async</span> getData () &#123;<br><span class="hljs-comment">// 获取服务器的数据, 对this.allData进行赋值之后, 调用updateChart方法更新图表</span><br><span class="hljs-keyword">const</span> &#123; <span class="hljs-attr">data</span>: ret &#125; = <span class="hljs-keyword">await</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">$http</span>.<span class="hljs-title function_">get</span>(<span class="hljs-string">&#x27;stock&#x27;</span>)<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">allData</span> = ret<br><span class="hljs-variable language_">this</span>.<span class="hljs-title function_">updateChart</span>()<br>&#125;<br></code></pre></td></tr></table></figure></li>
<li><p>数据的处理, 要显示 5 个圆环的实现</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><code class="hljs js">updateChart () &#123;<br><span class="hljs-comment">// 处理图表需要的数据</span><br><span class="hljs-comment">// 5个圆环对应的圆心点</span><br><span class="hljs-keyword">const</span> centerPointers = [<br>[<span class="hljs-string">&#x27;18%&#x27;</span>, <span class="hljs-string">&#x27;40%&#x27;</span>],<br>[<span class="hljs-string">&#x27;50%&#x27;</span>, <span class="hljs-string">&#x27;40%&#x27;</span>],<br>[<span class="hljs-string">&#x27;82%&#x27;</span>, <span class="hljs-string">&#x27;40%&#x27;</span>],<br>[<span class="hljs-string">&#x27;34%&#x27;</span>, <span class="hljs-string">&#x27;75%&#x27;</span>],<br>[<span class="hljs-string">&#x27;66%&#x27;</span>, <span class="hljs-string">&#x27;75%&#x27;</span>]<br>]<br><span class="hljs-comment">// 先显示前5条数据</span><br><span class="hljs-keyword">const</span> showData = <span class="hljs-variable language_">this</span>.<span class="hljs-property">allData</span>.<span class="hljs-title function_">slice</span>(<span class="hljs-number">0</span>, <span class="hljs-number">5</span>)<br><span class="hljs-keyword">const</span> seriesArr = showData.<span class="hljs-title function_">map</span>(<span class="hljs-function">(<span class="hljs-params">item, index</span>) =&gt;</span> &#123;<br><span class="hljs-keyword">return</span> &#123;<br><span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;pie&#x27;</span>,<br><span class="hljs-attr">center</span>: centerPointers[index],<br><span class="hljs-attr">radius</span>: [<span class="hljs-number">110</span>, <span class="hljs-number">100</span>],<br><span class="hljs-attr">data</span>: [<br>&#123;<br><span class="hljs-attr">value</span>: item.<span class="hljs-property">sales</span><br>&#125;,<br>&#123;<br><span class="hljs-attr">value</span>: item.<span class="hljs-property">stock</span>,<br>&#125;<br>]<br>&#125;<br>&#125;)<br><span class="hljs-keyword">const</span> dataOption = &#123;<br><span class="hljs-attr">series</span>: seriesArr<br>&#125;<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">chartInstance</span>.<span class="hljs-title function_">setOption</span>(dataOption)<br>&#125;,<br></code></pre></td></tr></table></figure></li>
<li><p>标题的配置</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs js">initChart () &#123;<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">chartInstance</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">$echarts</span>.<span class="hljs-title function_">init</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">$refs</span>.<span class="hljs-property">stock_ref</span>)<br><span class="hljs-keyword">const</span> initOption = &#123;<br><span class="hljs-attr">title</span>: &#123;<br><span class="hljs-attr">text</span>: <span class="hljs-string">&#x27;▎ 库存销售量&#x27;</span>,<br><span class="hljs-attr">left</span>: <span class="hljs-number">20</span>,<br><span class="hljs-attr">top</span>: <span class="hljs-number">20</span><br>&#125;<br>&#125;<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">chartInstance</span>.<span class="hljs-title function_">setOption</span>(initOption)<br>&#125;,<br></code></pre></td></tr></table></figure></li>
</ul>
<h2 id="UI-效果的调整"><a href="#UI-效果的调整" class="headerlink" title="UI 效果的调整"></a>UI 效果的调整</h2><ul>
<li><p>主题的使用</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-attr">methods</span>: &#123;<br>initChart () &#123;<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">chartInstance</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">$echarts</span>.<span class="hljs-title function_">init</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">$refs</span>.<span class="hljs-property">stock_ref</span>,<br><span class="hljs-string">&#x27;chalk&#x27;</span>)<br></code></pre></td></tr></table></figure></li>
<li><p>鼠标移入动画的移除</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs js">updateChart () &#123;<br>......<br><span class="hljs-keyword">const</span> seriesArr = showData.<span class="hljs-title function_">map</span>(<span class="hljs-function">(<span class="hljs-params">item, index</span>) =&gt;</span> &#123;<br><span class="hljs-keyword">return</span> &#123;<br>......<br><span class="hljs-attr">hoverAnimation</span>: <span class="hljs-literal">false</span>,<br></code></pre></td></tr></table></figure></li>
<li><p>指示线的移除</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs js">updateChart () &#123;<br>......<br><span class="hljs-keyword">const</span> seriesArr = showData.<span class="hljs-title function_">map</span>(<span class="hljs-function">(<span class="hljs-params">item, index</span>) =&gt;</span> &#123;<br><span class="hljs-keyword">return</span> &#123;<br>......<br><span class="hljs-attr">labelLine</span>: &#123;<br><span class="hljs-attr">show</span>: <span class="hljs-literal">false</span><br>&#125;,<br></code></pre></td></tr></table></figure></li>
<li><p>圆环内文字的显示</p>
<p>给饼图第一部分数据增加 name 属性</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs js">updateChart () &#123;<br>......<br><span class="hljs-keyword">const</span> seriesArr = showData.<span class="hljs-title function_">map</span>(<span class="hljs-function">(<span class="hljs-params">item, index</span>) =&gt;</span> &#123;<br><span class="hljs-keyword">return</span> &#123;<br>......<br><span class="hljs-attr">data</span>: [<br>&#123;<br><span class="hljs-attr">name</span>: item.<span class="hljs-property">name</span> + <span class="hljs-string">&#x27;\n\n&#x27;</span> + item.<span class="hljs-property">sales</span>,<br><span class="hljs-attr">value</span>: item.<span class="hljs-property">sales</span>,<br>......<br></code></pre></td></tr></table></figure>

<p>设置 label 的显示位置</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs js">updateChart () &#123;<br>......<br><span class="hljs-keyword">const</span> seriesArr = showData.<span class="hljs-title function_">map</span>(<span class="hljs-function">(<span class="hljs-params">item, index</span>) =&gt;</span> &#123;<br><span class="hljs-keyword">return</span> &#123;<br>.....<br><span class="hljs-attr">label</span>: &#123;<br><span class="hljs-attr">show</span>: <span class="hljs-literal">true</span>,<br><span class="hljs-attr">position</span>: <span class="hljs-string">&#x27;center&#x27;</span><br>&#125;,<br></code></pre></td></tr></table></figure></li>
<li><p>颜色的处理</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><code class="hljs js">updateChart () &#123;<br><span class="hljs-comment">// 增加5个圆环的渐变颜色范围</span><br><span class="hljs-keyword">const</span> colorArrs = [<br>[<span class="hljs-string">&#x27;#4FF778&#x27;</span>, <span class="hljs-string">&#x27;#0BA82C&#x27;</span>],<br>[<span class="hljs-string">&#x27;#E5DD45&#x27;</span>, <span class="hljs-string">&#x27;#E8B11C&#x27;</span>],<br>[<span class="hljs-string">&#x27;#E8821C&#x27;</span>, <span class="hljs-string">&#x27;#E55445&#x27;</span>],<br>[<span class="hljs-string">&#x27;#5052EE&#x27;</span>, <span class="hljs-string">&#x27;#AB6EE5&#x27;</span>],<br>[<span class="hljs-string">&#x27;#23E5E5&#x27;</span>, <span class="hljs-string">&#x27;#2E72BF&#x27;</span>]<br>]<br>......<br><span class="hljs-keyword">const</span> seriesArr = showData.<span class="hljs-title function_">map</span>(<span class="hljs-function">(<span class="hljs-params">item, index</span>) =&gt;</span> &#123;<br><span class="hljs-keyword">return</span> &#123;<br>......<br><span class="hljs-attr">label</span>: &#123;<br><span class="hljs-attr">show</span>: <span class="hljs-literal">true</span>,<br><span class="hljs-attr">position</span>: <span class="hljs-string">&#x27;center&#x27;</span>,<br><span class="hljs-attr">color</span>: colorArrs[index][<span class="hljs-number">0</span>]<br>&#125;,<br><span class="hljs-attr">data</span>: [<br>&#123;<br><span class="hljs-attr">name</span>: item.<span class="hljs-property">name</span> + <span class="hljs-string">&#x27;\n\n&#x27;</span> + item.<span class="hljs-property">sales</span>,<br><span class="hljs-attr">value</span>: item.<span class="hljs-property">sales</span>,<br><span class="hljs-attr">itemStyle</span>: &#123;<br><span class="hljs-attr">color</span>: <span class="hljs-keyword">new</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">$echarts</span>.<span class="hljs-property">graphic</span>.<span class="hljs-title class_">LinearGradient</span>(<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>,<br>[<br>&#123;<br><span class="hljs-attr">offset</span>: <span class="hljs-number">0</span>,<br><span class="hljs-attr">color</span>: colorArrs[index][<span class="hljs-number">0</span>]<br>&#125;,<br>&#123;<br><span class="hljs-attr">offset</span>: <span class="hljs-number">1</span>,<br><span class="hljs-attr">color</span>: colorArrs[index][<span class="hljs-number">1</span>]<br>&#125;<br>])<br>&#125;<br>&#125;,<br>&#123;<br><span class="hljs-attr">value</span>: item.<span class="hljs-property">stock</span>,<br><span class="hljs-attr">itemStyle</span>: &#123;<br><span class="hljs-attr">color</span>: <span class="hljs-string">&#x27;#333843&#x27;</span><br>&#125;<br>&#125;<br>]<br>&#125;<br>&#125;)<br><span class="hljs-keyword">const</span> dataOption = &#123;<br><span class="hljs-attr">series</span>: seriesArr<br>&#125;<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">chartInstance</span>.<span class="hljs-title function_">setOption</span>(dataOption)<br>&#125;,<br></code></pre></td></tr></table></figure></li>
</ul>
<h2 id="切换动画"><a href="#切换动画" class="headerlink" title="切换动画"></a>切换动画</h2><ul>
<li><p>增加数据 <code>currentIndex</code> ,标识当前的页数</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs js">&lt;script&gt;<br><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> &#123;<br>data () &#123;<br><span class="hljs-keyword">return</span> &#123;<br>......<br><span class="hljs-attr">currentIndex</span>: <span class="hljs-number">0</span>,<br><span class="hljs-attr">timerId</span>: <span class="hljs-literal">null</span><br>&#125;<br>&#125;,<br></code></pre></td></tr></table></figure></li>
<li><p>根据 <code>currentIndex</code> 决定展示的数据</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs js">updateChart () &#123;<br>......<br><span class="hljs-keyword">const</span> start = <span class="hljs-variable language_">this</span>.<span class="hljs-property">currentIndex</span> * <span class="hljs-number">5</span><br><span class="hljs-keyword">const</span> end = (<span class="hljs-variable language_">this</span>.<span class="hljs-property">currentIndex</span> + <span class="hljs-number">1</span>) * <span class="hljs-number">5</span><br><span class="hljs-keyword">const</span> showData = <span class="hljs-variable language_">this</span>.<span class="hljs-property">allData</span>.<span class="hljs-title function_">slice</span>(start, end)<br><span class="hljs-keyword">const</span> seriesArr = showData.<span class="hljs-title function_">map</span>(<span class="hljs-function">(<span class="hljs-params">item, index</span>) =&gt;</span> &#123;<br>......<br></code></pre></td></tr></table></figure></li>
<li><p>数据获取成功之后启动动画</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-keyword">async</span> getData () &#123;<br><span class="hljs-comment">// 获取服务器的数据, 对this.allData进行赋值之后, 调用updateChart方法更新图表</span><br><span class="hljs-keyword">const</span> &#123; <span class="hljs-attr">data</span>: ret &#125; = <span class="hljs-keyword">await</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">$http</span>.<span class="hljs-title function_">get</span>(<span class="hljs-string">&#x27;stock&#x27;</span>)<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">allData</span> = ret<br><span class="hljs-variable language_">this</span>.<span class="hljs-title function_">updateChart</span>()<br><span class="hljs-variable language_">this</span>.<span class="hljs-title function_">startInterval</span>()<br>&#125;,<br>......<br>startInterval () &#123;<br><span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">timerId</span>) &#123;<br><span class="hljs-built_in">clearInterval</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">timerId</span>)<br>&#125;<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">timerId</span> = <span class="hljs-built_in">setInterval</span>(<span class="hljs-function">() =&gt;</span> &#123;<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">currentIndex</span>++<br><span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">currentIndex</span> &gt; <span class="hljs-number">1</span>) &#123;<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">currentIndex</span> = <span class="hljs-number">0</span><br>&#125;<br><span class="hljs-variable language_">this</span>.<span class="hljs-title function_">updateChart</span>()<br>&#125;, <span class="hljs-number">3000</span>)<br>&#125;<br></code></pre></td></tr></table></figure></li>
<li><p>组件销毁时停止动画</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs js">destroyed () &#123;<br><span class="hljs-variable language_">window</span>.<span class="hljs-title function_">removeEventListener</span>(<span class="hljs-string">&#x27;resize&#x27;</span>, <span class="hljs-variable language_">this</span>.<span class="hljs-property">screenAdapter</span>)<br><span class="hljs-built_in">clearInterval</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">timerId</span>)<br>&#125;,<br></code></pre></td></tr></table></figure></li>
<li><p>鼠标事件的处理</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-attr">methods</span>: &#123;<br>initChart () &#123;<br>......<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">chartInstance</span>.<span class="hljs-title function_">on</span>(<span class="hljs-string">&#x27;mouseover&#x27;</span>, <span class="hljs-function">() =&gt;</span> &#123;<br><span class="hljs-built_in">clearInterval</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">timerId</span>)<br>&#125;)<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">chartInstance</span>.<span class="hljs-title function_">on</span>(<span class="hljs-string">&#x27;mouseout&#x27;</span>, <span class="hljs-function">() =&gt;</span> &#123;<br><span class="hljs-variable language_">this</span>.<span class="hljs-title function_">startInterval</span>()<br>&#125;)<br>&#125;,<br></code></pre></td></tr></table></figure></li>
</ul>
<h2 id="分辨率适配"><a href="#分辨率适配" class="headerlink" title="分辨率适配"></a>分辨率适配</h2><p>分辨率适配主要就是在 <code>screenAdapter</code> 方法中进行, 需要获取图表容器的宽度,计算出标题字体大小, 将字体的大小赋值给 <code>titleFontSize</code></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs js">&lt;script&gt;<br><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> &#123;<br>data () &#123;<br><span class="hljs-keyword">return</span> &#123;<br>......<br><span class="hljs-attr">titleFontSize</span>: <span class="hljs-number">0</span><br>&#125;<br>&#125;,<br>......<br>screenAdapter () &#123;<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">titleFontSize</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">$refs</span>.<span class="hljs-property">stock_ref</span>.<span class="hljs-property">offsetWidth</span> / <span class="hljs-number">100</span> * <span class="hljs-number">3.6</span><br>&#125;<br></code></pre></td></tr></table></figure>

<p>通过 <code>titleFontSize</code> 从而设置给图表某些区域</p>
<ul>
<li><p>标题大小</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs js">screenAdapter () &#123;<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">titleFontSize</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">$refs</span>.<span class="hljs-property">stock_ref</span>.<span class="hljs-property">offsetWidth</span> / <span class="hljs-number">100</span> * <span class="hljs-number">3.6</span><br><span class="hljs-keyword">const</span> adapterOption = &#123;<br><span class="hljs-attr">title</span>: &#123;<br><span class="hljs-attr">textStyle</span>: &#123;<br><span class="hljs-attr">fontSize</span>: <span class="hljs-variable language_">this</span>.<span class="hljs-property">titleFontSize</span><br>&#125;<br>&#125;<br>&#125;<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">chartInstance</span>.<span class="hljs-title function_">setOption</span>(adapterOption)<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">chartInstance</span>.<span class="hljs-title function_">resize</span>()<br>&#125;,<br></code></pre></td></tr></table></figure></li>
<li><p>圆环半径和圆环文字</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><code class="hljs js">screenAdapter () &#123;<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">titleFontSize</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">$refs</span>.<span class="hljs-property">stock_ref</span>.<span class="hljs-property">offsetWidth</span> / <span class="hljs-number">100</span> * <span class="hljs-number">3.6</span><br><span class="hljs-keyword">const</span> innerRadius = <span class="hljs-variable language_">this</span>.<span class="hljs-property">titleFontSize</span> * <span class="hljs-number">2</span><br><span class="hljs-keyword">const</span> outterRadius = innerRadius * <span class="hljs-number">1.125</span><br><span class="hljs-keyword">const</span> adapterOption = &#123;<br><span class="hljs-attr">title</span>: &#123;<br><span class="hljs-attr">textStyle</span>: &#123;<br><span class="hljs-attr">fontSize</span>: <span class="hljs-variable language_">this</span>.<span class="hljs-property">titleFontSize</span><br>&#125;<br>&#125;,<br><span class="hljs-attr">series</span>: [<br>&#123;<br><span class="hljs-attr">radius</span>: [outterRadius, innerRadius],<br><span class="hljs-attr">label</span>: &#123;<br><span class="hljs-attr">fontSize</span>: <span class="hljs-variable language_">this</span>.<span class="hljs-property">titleFontSize</span> / <span class="hljs-number">2</span><br>&#125;<br>&#125;,<br>&#123;<br><span class="hljs-attr">radius</span>: [outterRadius, innerRadius],<br><span class="hljs-attr">label</span>: &#123;<br><span class="hljs-attr">fontSize</span>: <span class="hljs-variable language_">this</span>.<span class="hljs-property">titleFontSize</span> / <span class="hljs-number">2</span><br>&#125;<br>&#125;,<br>&#123;<br><span class="hljs-attr">radius</span>: [outterRadius, innerRadius],<br><span class="hljs-attr">label</span>: &#123;<br><span class="hljs-attr">fontSize</span>: <span class="hljs-variable language_">this</span>.<span class="hljs-property">titleFontSize</span> / <span class="hljs-number">2</span><br>&#125;<br>&#125;,<br>&#123;<br><span class="hljs-attr">radius</span>: [outterRadius, innerRadius],<br><span class="hljs-attr">label</span>: &#123;<br><span class="hljs-attr">fontSize</span>: <span class="hljs-variable language_">this</span>.<span class="hljs-property">titleFontSize</span> / <span class="hljs-number">2</span><br>&#125;<br>&#125;,<br>&#123;<br><span class="hljs-attr">radius</span>: [outterRadius, innerRadius],<br><span class="hljs-attr">label</span>: &#123;<br><span class="hljs-attr">fontSize</span>: <span class="hljs-variable language_">this</span>.<span class="hljs-property">titleFontSize</span> / <span class="hljs-number">2</span><br>&#125;<br>&#125;<br>]<br>&#125;<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">chartInstance</span>.<span class="hljs-title function_">setOption</span>(adapterOption)<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">chartInstance</span>.<span class="hljs-title function_">resize</span>()<br>&#125;<br></code></pre></td></tr></table></figure></li>
<li><p>调整 <code>initOption 和 dataOption</code></p>
<p><code>initOption</code></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-attr">methods</span>: &#123;<br>initChart () &#123;<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">chartInstance</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">$echarts</span>.<span class="hljs-title function_">init</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">$refs</span>.<span class="hljs-property">stock_ref</span>,<br><span class="hljs-string">&#x27;chalk&#x27;</span>)<br><span class="hljs-keyword">const</span> centerPointers = [<br>[<span class="hljs-string">&#x27;18%&#x27;</span>, <span class="hljs-string">&#x27;40%&#x27;</span>],<br>[<span class="hljs-string">&#x27;50%&#x27;</span>, <span class="hljs-string">&#x27;40%&#x27;</span>],<br>[<span class="hljs-string">&#x27;82%&#x27;</span>, <span class="hljs-string">&#x27;40%&#x27;</span>],<br>[<span class="hljs-string">&#x27;34%&#x27;</span>, <span class="hljs-string">&#x27;75%&#x27;</span>],<br>[<span class="hljs-string">&#x27;66%&#x27;</span>, <span class="hljs-string">&#x27;75%&#x27;</span>]<br>]<br><span class="hljs-keyword">const</span> initOption = &#123;<br><span class="hljs-attr">title</span>: &#123;<br><span class="hljs-attr">text</span>: <span class="hljs-string">&#x27;▎ 库存销售量&#x27;</span>,<br><span class="hljs-attr">left</span>: <span class="hljs-number">20</span>,<br><span class="hljs-attr">top</span>: <span class="hljs-number">20</span><br>&#125;,<br><span class="hljs-attr">series</span>: [<br>&#123;<br><span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;pie&#x27;</span>,<br><span class="hljs-attr">center</span>: centerPointers[<span class="hljs-number">0</span>],<br><span class="hljs-attr">hoverAnimation</span>: <span class="hljs-literal">false</span>,<br><span class="hljs-attr">label</span>: &#123;<br><span class="hljs-attr">show</span>: <span class="hljs-literal">true</span>,<br><span class="hljs-attr">position</span>: <span class="hljs-string">&#x27;center&#x27;</span><br>&#125;,<br><span class="hljs-attr">labelLine</span>: &#123;<br><span class="hljs-attr">show</span>: <span class="hljs-literal">false</span><br>&#125;<br>&#125;,<br>&#123;<br><span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;pie&#x27;</span>,<br><span class="hljs-attr">center</span>: centerPointers[<span class="hljs-number">1</span>],<br><span class="hljs-attr">hoverAnimation</span>: <span class="hljs-literal">false</span>,<br><span class="hljs-attr">label</span>: &#123;<br><span class="hljs-attr">show</span>: <span class="hljs-literal">true</span>,<br><span class="hljs-attr">position</span>: <span class="hljs-string">&#x27;center&#x27;</span><br>&#125;,<br><span class="hljs-attr">labelLine</span>: &#123;<br><span class="hljs-attr">show</span>: <span class="hljs-literal">false</span><br>&#125;<br>&#125;,<br>&#123;<br><span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;pie&#x27;</span>,<br><span class="hljs-attr">center</span>: centerPointers[<span class="hljs-number">2</span>],<br><span class="hljs-attr">hoverAnimation</span>: <span class="hljs-literal">false</span>,<br><span class="hljs-attr">label</span>: &#123;<br><span class="hljs-attr">show</span>: <span class="hljs-literal">true</span>,<br><span class="hljs-attr">position</span>: <span class="hljs-string">&#x27;center&#x27;</span><br>&#125;,<br><span class="hljs-attr">labelLine</span>: &#123;<br><span class="hljs-attr">show</span>: <span class="hljs-literal">false</span><br>&#125;<br>&#125;,<br>&#123;<br><span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;pie&#x27;</span>,<br><span class="hljs-attr">center</span>: centerPointers[<span class="hljs-number">3</span>],<br><span class="hljs-attr">hoverAnimation</span>: <span class="hljs-literal">false</span>,<br><span class="hljs-attr">label</span>: &#123;<br><span class="hljs-attr">show</span>: <span class="hljs-literal">true</span>,<br><span class="hljs-attr">position</span>: <span class="hljs-string">&#x27;center&#x27;</span><br>&#125;,<br><span class="hljs-attr">labelLine</span>: &#123;<br><span class="hljs-attr">show</span>: <span class="hljs-literal">false</span><br>&#125;<br>&#125;,<br>&#123;<br><span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;pie&#x27;</span>,<br><span class="hljs-attr">center</span>: centerPointers[<span class="hljs-number">4</span>],<br><span class="hljs-attr">hoverAnimation</span>: <span class="hljs-literal">false</span>,<br><span class="hljs-attr">label</span>: &#123;<br><span class="hljs-attr">show</span>: <span class="hljs-literal">true</span>,<br><span class="hljs-attr">position</span>: <span class="hljs-string">&#x27;center&#x27;</span><br>&#125;,<br><span class="hljs-attr">labelLine</span>: &#123;<br><span class="hljs-attr">show</span>: <span class="hljs-literal">false</span><br>&#125;<br>&#125;<br>]<br>&#125;<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">chartInstance</span>.<span class="hljs-title function_">setOption</span>(initOption)<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">chartInstance</span>.<span class="hljs-title function_">on</span>(<span class="hljs-string">&#x27;mouseover&#x27;</span>, <span class="hljs-function">() =&gt;</span> &#123;<br><span class="hljs-built_in">clearInterval</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">timerId</span>)<br>&#125;)<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">chartInstance</span>.<span class="hljs-title function_">on</span>(<span class="hljs-string">&#x27;mouseout&#x27;</span>, <span class="hljs-function">() =&gt;</span> &#123;<br><span class="hljs-variable language_">this</span>.<span class="hljs-title function_">startInterval</span>()<br>&#125;)<br>&#125;,<br></code></pre></td></tr></table></figure>

<p><code>dataOption</code></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><code class="hljs js">updateChart () &#123;<br><span class="hljs-comment">// 处理图表需要的数据</span><br><span class="hljs-keyword">const</span> colorArrs = [<br>[<span class="hljs-string">&#x27;#4FF778&#x27;</span>, <span class="hljs-string">&#x27;#0BA82C&#x27;</span>],<br>[<span class="hljs-string">&#x27;#E5DD45&#x27;</span>, <span class="hljs-string">&#x27;#E8B11C&#x27;</span>],<br>[<span class="hljs-string">&#x27;#E8821C&#x27;</span>, <span class="hljs-string">&#x27;#E55445&#x27;</span>],<br>[<span class="hljs-string">&#x27;#5052EE&#x27;</span>, <span class="hljs-string">&#x27;#AB6EE5&#x27;</span>],<br>[<span class="hljs-string">&#x27;#23E5E5&#x27;</span>, <span class="hljs-string">&#x27;#2E72BF&#x27;</span>],<br>]<br><span class="hljs-keyword">const</span> start = <span class="hljs-variable language_">this</span>.<span class="hljs-property">currentIndex</span> * <span class="hljs-number">5</span><br><span class="hljs-keyword">const</span> end = (<span class="hljs-variable language_">this</span>.<span class="hljs-property">currentIndex</span> + <span class="hljs-number">1</span>) * <span class="hljs-number">5</span><br><span class="hljs-keyword">const</span> showData = <span class="hljs-variable language_">this</span>.<span class="hljs-property">allData</span>.<span class="hljs-title function_">slice</span>(start, end)<br><span class="hljs-keyword">const</span> seriesArr = showData.<span class="hljs-title function_">map</span>(<span class="hljs-function">(<span class="hljs-params">item, index</span>) =&gt;</span> &#123;<br><span class="hljs-keyword">return</span> &#123;<br><span class="hljs-attr">label</span>: &#123;<br><span class="hljs-attr">color</span>: colorArrs[index][<span class="hljs-number">0</span>]<br>&#125;,<br><span class="hljs-attr">data</span>: [<br>&#123;<br><span class="hljs-attr">name</span>: item.<span class="hljs-property">name</span> + <span class="hljs-string">&#x27;\n\n&#x27;</span> + item.<span class="hljs-property">sales</span>,<br><span class="hljs-attr">value</span>: item.<span class="hljs-property">sales</span>,<br><span class="hljs-attr">itemStyle</span>: &#123;<br><span class="hljs-attr">color</span>: <span class="hljs-keyword">new</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">$echarts</span>.<span class="hljs-property">graphic</span>.<span class="hljs-title class_">LinearGradient</span>(<span class="hljs-number">0</span>,<br><span class="hljs-number">1</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, [<br>&#123;<br><span class="hljs-attr">offset</span>: <span class="hljs-number">0</span>,<br><span class="hljs-attr">color</span>: colorArrs[index][<span class="hljs-number">0</span>]<br>&#125;,<br>&#123;<br><span class="hljs-attr">offset</span>: <span class="hljs-number">1</span>,<br><span class="hljs-attr">color</span>: colorArrs[index][<span class="hljs-number">1</span>]<br>&#125;<br>])<br>&#125;<br>&#125;,<br>&#123;<br><span class="hljs-attr">value</span>: item.<span class="hljs-property">stock</span>,<br><span class="hljs-attr">itemStyle</span>: &#123;<br><span class="hljs-attr">color</span>: <span class="hljs-string">&#x27;#333843&#x27;</span><br>&#125;<br>&#125;<br>]<br>&#125;<br>&#125;)<br><span class="hljs-keyword">const</span> dataOption = &#123;<br><span class="hljs-attr">series</span>: seriesArr<br>&#125;<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">chartInstance</span>.<span class="hljs-title function_">setOption</span>(dataOption)<br>&#125;<br></code></pre></td></tr></table></figure></li>
</ul>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E6%95%B0%E6%8D%AE%E5%8F%AF%E8%A7%86%E5%8C%96%E9%A1%B9%E7%9B%AE/" class="category-chain-item">数据可视化项目</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/echarts/">#echarts</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>数据可视化项目七</div>
      <div>http://example.com/2022/11/17/数据可视化项目八/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>dayu</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年11月17日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/11/18/%E6%95%B0%E6%8D%AE%E5%8F%AF%E8%A7%86%E5%8C%96%E9%A1%B9%E7%9B%AE%E4%B9%9D/" title="数据可视化项目九">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">数据可视化项目九</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/11/17/%E6%95%B0%E6%8D%AE%E5%8F%AF%E8%A7%86%E5%8C%96%E9%A1%B9%E7%9B%AE%E4%B8%83/" title="数据可视化项目八">
                        <span class="hidden-mobile">数据可视化项目八</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
